package huaweiod.third;

import java.util.*;

/**
 * 模拟消息队列
 * https://fcqian.blog.csdn.net/article/details/130764579
 */
public class B_MockMessageQueue {

    static class Product {
        public int time;
        public int msg;

        public Product(int time, int msg) {
            this.time = time;
            this.msg = msg;
        }
    }

    static class Consumer {
        public int start;
        public int end;
        public int prior;

        public Consumer(int start, int end, int prior) {
            this.start = start;
            this.end = end;
            this.prior = prior;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] s1 = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] s2 = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        List<Product> products = new ArrayList<>();
        List<Consumer> consumers = new ArrayList<>();
        for (int i = 0; i < s1.length; i++, i++) {
            products.add(new Product(s1[i], s1[i + 1]));
        }
        for (int i = 0; i < s2.length; i++, i++) {
            consumers.add(new Consumer(s2[i], s2[i + 1], i / 2));
        }
        products.sort((o1, o2) -> o1.time - o2.time);
        consumers.sort((o1, o2) -> o2.prior - o1.prior);
        StringJoiner[] ans = new StringJoiner[consumers.size()];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = new StringJoiner(" ");
        }
        for (Product product : products) {
            for (Consumer consumer : consumers) {
                if (consumer.start <= product.time && consumer.end > product.time) {
                    ans[consumer.prior].add(String.valueOf(product.msg));
                    break;
                }
            }
        }
        for (StringJoiner sj : ans) {
            System.out.println(sj);
        }
    }
}
